// POST:/admin/products/create
//   {name, pic, category, intro, price}

export default {
  getProducts: (page, scb, fcb) => {
    // scb({list:[{id:1,'name':'', price: '30', category:'数码', intro:'intro', src:'/product.jpg'},{id:2,'name':'', price: '30', category:'数码', intro:'intro', src:'/product.jpg'}],page:1, total:50})
    fetch('/getProduct/' + page, {
      credentials: 'include',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        price: 77
      })
      }).then((res) => {
        return res.json()
      }).then((json) => {
        console.log('get products: ', json)
        scb(json)
    })
  },
  createProduct: (product, scb, fcb) => {
    console.log('create:', product)
    fetch('/admin/products/create', {
      credentials: 'include',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        ...product
      })
      }).then((res) => {
        return res.json()
      }).then((json) => {
        console.log('add products: ', json)
        scb()
      })
  }
}
